package com.yjm.test.Spring5.ch3.beanName;

import java.util.Arrays;
import java.util.Map;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.GenericApplicationContext;

import com.yjm.test.Spring5.ch3.Singer;

public class AliasAnnotationConfig {

	@Configuration
	@ComponentScan(basePackages="com.yjm.test.Spring5.ch3.beanName")
	public static class AliasBeanConfig {
		@Bean(name= {"johnMayer","john","johnny","xy"})
		public Singer singer() {
			return new Singer();
		}
	}
	
	public static void main(String[] args) {
		GenericApplicationContext ctx = new AnnotationConfigApplicationContext(AliasBeanConfig.class);

		Map<String, com.yjm.test.Spring5.ch5.Singer> beans = ctx.getBeansOfType(com.yjm.test.Spring5.ch5.Singer.class);
		beans.entrySet().stream().forEach(b -> {
			System.out.println("id:" + b.getKey() + "\taliases:" + Arrays.toString(ctx.getAliases(b.getKey())));
		});

	}

}
